package com.jdbcTemplate.transactional;

import org.springframework.aop.framework.AopContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author CKC
 * @date 2022/11/21 12:14
 */
@Component
public class Demo {
    @Resource
    private JdbcTemplate jdbcTemplate;

    @Transactional(propagation = Propagation.REQUIRED)
    public void test1() {
        jdbcTemplate.execute("insert into t_aa value (1,1,1,1,1,1)");
        Demo demo = (Demo) AopContext.currentProxy();
        demo.test2();
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void test2() {
        jdbcTemplate.execute("insert into t_aa value (2,2,2,2,2,2)");
    }


}
